Imports cmplib01

Public Class ctlCreateBattleGroups
    Inherits System.Windows.Forms.UserControl

    Public Event PointValueChanged(ByVal newvalue As Integer)

    Private ptrUnit As BattlegroupChit
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents btnAddBattleGroup As System.Windows.Forms.Button
    Private ptrCurrentGame As CampaignerGameData
    Private _selectedGroup As BattlegroupChit
    Private battleGroupNode As CampaignerItemTreeNode


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlCreateBattlegroup As System.Windows.Forms.Panel
    Friend WithEvents lblBattlegroupHeader As System.Windows.Forms.Label
    Friend WithEvents tvwBattlegroupView As System.Windows.Forms.TreeView
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents lblBGName As System.Windows.Forms.Label
    Friend WithEvents pnlIcons As System.Windows.Forms.Panel
    Friend WithEvents lblClickitbaby As System.Windows.Forms.Label
    Friend WithEvents lblFriendly As System.Windows.Forms.Label
    Friend WithEvents lblEnemy As System.Windows.Forms.Label
    Friend WithEvents lblOwner As System.Windows.Forms.Label
    Friend WithEvents picFriendly As System.Windows.Forms.PictureBox
    Friend WithEvents picEnemy As System.Windows.Forms.PictureBox
    Friend WithEvents picOwner As System.Windows.Forms.PictureBox
    Friend WithEvents lblBGPointValue As System.Windows.Forms.Label
    Friend WithEvents btnRemoveUnit As System.Windows.Forms.Button
    Friend WithEvents btnAddNewUnit As System.Windows.Forms.Button
    Friend WithEvents txtBattlegroupName As System.Windows.Forms.TextBox
    Friend WithEvents btnEditUnit As System.Windows.Forms.Button
    Friend WithEvents imlUnitIcons As System.Windows.Forms.ImageList
    Friend WithEvents lblBattlegroupIcons As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim TreeNode1 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Lieutenant")
        Dim TreeNode2 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Rifleman")
        Dim TreeNode3 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Rifleman")
        Dim TreeNode4 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Rifleman")
        Dim TreeNode5 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Medic")
        Dim TreeNode6 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Platoon HQ", New System.Windows.Forms.TreeNode() {TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNode5})
        Dim TreeNode7 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node17")
        Dim TreeNode8 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("1st Squad", New System.Windows.Forms.TreeNode() {TreeNode7})
        Dim TreeNode9 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node16")
        Dim TreeNode10 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("2nd Squad", New System.Windows.Forms.TreeNode() {TreeNode9})
        Dim TreeNode11 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node15")
        Dim TreeNode12 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("3rd Squad", New System.Windows.Forms.TreeNode() {TreeNode11})
        Dim TreeNode13 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("1st Platoon", New System.Windows.Forms.TreeNode() {TreeNode6, TreeNode8, TreeNode10, TreeNode12})
        Dim TreeNode14 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node18")
        Dim TreeNode15 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("2nd Platoon", New System.Windows.Forms.TreeNode() {TreeNode14})
        Dim TreeNode16 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Ungrouped")
        Dim TreeNode17 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("8x Infantry")
        Dim TreeNode18 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("1x Infantry (lascannon)")
        Dim TreeNode19 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("1x Infantry (flamer)")
        Dim TreeNode20 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Chimera")
        Dim TreeNode21 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("204", New System.Windows.Forms.TreeNode() {TreeNode17, TreeNode18, TreeNode19, TreeNode20})
        Dim TreeNode22 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("204 Armored Fist", New System.Windows.Forms.TreeNode() {TreeNode16, TreeNode21})
        Dim TreeNode23 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Node20")
        Dim TreeNode24 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Support Platoon", New System.Windows.Forms.TreeNode() {TreeNode23})
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ctlCreateBattleGroups))
        Me.pnlCreateBattlegroup = New System.Windows.Forms.Panel
        Me.lblBattlegroupIcons = New System.Windows.Forms.Label
        Me.btnEditUnit = New System.Windows.Forms.Button
        Me.btnAddNewUnit = New System.Windows.Forms.Button
        Me.btnRemoveUnit = New System.Windows.Forms.Button
        Me.lblBGPointValue = New System.Windows.Forms.Label
        Me.lblBattlegroupHeader = New System.Windows.Forms.Label
        Me.tvwBattlegroupView = New System.Windows.Forms.TreeView
        Me.imlUnitIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.Label11 = New System.Windows.Forms.Label
        Me.txtBattlegroupName = New System.Windows.Forms.TextBox
        Me.lblBGName = New System.Windows.Forms.Label
        Me.pnlIcons = New System.Windows.Forms.Panel
        Me.lblClickitbaby = New System.Windows.Forms.Label
        Me.lblFriendly = New System.Windows.Forms.Label
        Me.lblEnemy = New System.Windows.Forms.Label
        Me.lblOwner = New System.Windows.Forms.Label
        Me.picFriendly = New System.Windows.Forms.PictureBox
        Me.picEnemy = New System.Windows.Forms.PictureBox
        Me.picOwner = New System.Windows.Forms.PictureBox
        Me.btnAddBattleGroup = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.pnlCreateBattlegroup.SuspendLayout()
        Me.pnlIcons.SuspendLayout()
        CType(Me.picFriendly, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picEnemy, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picOwner, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'pnlCreateBattlegroup
        '
        Me.pnlCreateBattlegroup.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlCreateBattlegroup.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlCreateBattlegroup.Controls.Add(Me.Button2)
        Me.pnlCreateBattlegroup.Controls.Add(Me.btnAddBattleGroup)
        Me.pnlCreateBattlegroup.Controls.Add(Me.lblBattlegroupIcons)
        Me.pnlCreateBattlegroup.Controls.Add(Me.btnEditUnit)
        Me.pnlCreateBattlegroup.Controls.Add(Me.btnAddNewUnit)
        Me.pnlCreateBattlegroup.Controls.Add(Me.btnRemoveUnit)
        Me.pnlCreateBattlegroup.Controls.Add(Me.lblBGPointValue)
        Me.pnlCreateBattlegroup.Controls.Add(Me.lblBattlegroupHeader)
        Me.pnlCreateBattlegroup.Controls.Add(Me.tvwBattlegroupView)
        Me.pnlCreateBattlegroup.Controls.Add(Me.Label11)
        Me.pnlCreateBattlegroup.Controls.Add(Me.txtBattlegroupName)
        Me.pnlCreateBattlegroup.Controls.Add(Me.lblBGName)
        Me.pnlCreateBattlegroup.Controls.Add(Me.pnlIcons)
        Me.pnlCreateBattlegroup.Location = New System.Drawing.Point(0, 0)
        Me.pnlCreateBattlegroup.Name = "pnlCreateBattlegroup"
        Me.pnlCreateBattlegroup.Size = New System.Drawing.Size(568, 367)
        Me.pnlCreateBattlegroup.TabIndex = 24
        '
        'lblBattlegroupIcons
        '
        Me.lblBattlegroupIcons.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblBattlegroupIcons.Location = New System.Drawing.Point(328, 264)
        Me.lblBattlegroupIcons.Name = "lblBattlegroupIcons"
        Me.lblBattlegroupIcons.Size = New System.Drawing.Size(104, 24)
        Me.lblBattlegroupIcons.TabIndex = 42
        Me.lblBattlegroupIcons.Text = "Battlegroup Icons"
        '
        'btnEditUnit
        '
        Me.btnEditUnit.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnEditUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditUnit.Location = New System.Drawing.Point(323, 109)
        Me.btnEditUnit.Name = "btnEditUnit"
        Me.btnEditUnit.Size = New System.Drawing.Size(101, 23)
        Me.btnEditUnit.TabIndex = 2
        Me.btnEditUnit.Text = "Edit Unit"
        Me.btnEditUnit.UseVisualStyleBackColor = False
        '
        'btnAddNewUnit
        '
        Me.btnAddNewUnit.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnAddNewUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAddNewUnit.Location = New System.Drawing.Point(323, 80)
        Me.btnAddNewUnit.Name = "btnAddNewUnit"
        Me.btnAddNewUnit.Size = New System.Drawing.Size(101, 23)
        Me.btnAddNewUnit.TabIndex = 1
        Me.btnAddNewUnit.Text = "Add New Unit"
        Me.btnAddNewUnit.UseVisualStyleBackColor = False
        '
        'btnRemoveUnit
        '
        Me.btnRemoveUnit.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnRemoveUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnRemoveUnit.Location = New System.Drawing.Point(323, 138)
        Me.btnRemoveUnit.Name = "btnRemoveUnit"
        Me.btnRemoveUnit.Size = New System.Drawing.Size(101, 23)
        Me.btnRemoveUnit.TabIndex = 3
        Me.btnRemoveUnit.Text = "Remove Unit"
        Me.btnRemoveUnit.UseVisualStyleBackColor = False
        '
        'lblBGPointValue
        '
        Me.lblBGPointValue.BackColor = System.Drawing.Color.White
        Me.lblBGPointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblBGPointValue.Location = New System.Drawing.Point(416, 32)
        Me.lblBGPointValue.Name = "lblBGPointValue"
        Me.lblBGPointValue.Size = New System.Drawing.Size(120, 21)
        Me.lblBGPointValue.TabIndex = 41
        Me.lblBGPointValue.Text = "0"
        Me.lblBGPointValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblBattlegroupHeader
        '
        Me.lblBattlegroupHeader.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.lblBattlegroupHeader.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblBattlegroupHeader.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblBattlegroupHeader.Location = New System.Drawing.Point(8, 64)
        Me.lblBattlegroupHeader.Name = "lblBattlegroupHeader"
        Me.lblBattlegroupHeader.Size = New System.Drawing.Size(304, 17)
        Me.lblBattlegroupHeader.TabIndex = 38
        Me.lblBattlegroupHeader.Text = "Battlegroup"
        '
        'tvwBattlegroupView
        '
        Me.tvwBattlegroupView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwBattlegroupView.ImageIndex = 0
        Me.tvwBattlegroupView.ImageList = Me.imlUnitIcons
        Me.tvwBattlegroupView.Location = New System.Drawing.Point(8, 80)
        Me.tvwBattlegroupView.Name = "tvwBattlegroupView"
        TreeNode1.Name = ""
        TreeNode1.Text = "Lieutenant"
        TreeNode2.Name = ""
        TreeNode2.Text = "Rifleman"
        TreeNode3.Name = ""
        TreeNode3.Text = "Rifleman"
        TreeNode4.Name = "Node1"
        TreeNode4.Text = "Rifleman"
        TreeNode5.Name = "Node2"
        TreeNode5.Text = "Medic"
        TreeNode6.Name = ""
        TreeNode6.Text = "Platoon HQ"
        TreeNode7.Name = ""
        TreeNode7.Text = "Node17"
        TreeNode8.Name = ""
        TreeNode8.Text = "1st Squad"
        TreeNode9.Name = ""
        TreeNode9.Text = "Node16"
        TreeNode10.Name = ""
        TreeNode10.Text = "2nd Squad"
        TreeNode11.Name = ""
        TreeNode11.Text = "Node15"
        TreeNode12.Name = ""
        TreeNode12.Text = "3rd Squad"
        TreeNode13.Name = ""
        TreeNode13.Text = "1st Platoon"
        TreeNode14.Name = ""
        TreeNode14.Text = "Node18"
        TreeNode15.Name = ""
        TreeNode15.Text = "2nd Platoon"
        TreeNode16.Name = ""
        TreeNode16.Text = "Ungrouped"
        TreeNode17.Name = ""
        TreeNode17.Text = "8x Infantry"
        TreeNode18.Name = ""
        TreeNode18.Text = "1x Infantry (lascannon)"
        TreeNode19.Name = ""
        TreeNode19.Text = "1x Infantry (flamer)"
        TreeNode20.Name = ""
        TreeNode20.Text = "Chimera"
        TreeNode21.Name = ""
        TreeNode21.Text = "204"
        TreeNode22.Name = ""
        TreeNode22.Text = "204 Armored Fist"
        TreeNode23.Name = ""
        TreeNode23.Text = "Node20"
        TreeNode24.Name = ""
        TreeNode24.Text = "Support Platoon"
        Me.tvwBattlegroupView.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode13, TreeNode15, TreeNode22, TreeNode24})
        Me.tvwBattlegroupView.SelectedImageIndex = 0
        Me.tvwBattlegroupView.Size = New System.Drawing.Size(304, 280)
        Me.tvwBattlegroupView.TabIndex = 37
        '
        'imlUnitIcons
        '
        Me.imlUnitIcons.ImageStream = CType(resources.GetObject("imlUnitIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlUnitIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlUnitIcons.Images.SetKeyName(0, "")
        Me.imlUnitIcons.Images.SetKeyName(1, "")
        Me.imlUnitIcons.Images.SetKeyName(2, "")
        '
        'Label11
        '
        Me.Label11.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label11.Location = New System.Drawing.Point(320, 36)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(104, 24)
        Me.Label11.TabIndex = 34
        Me.Label11.Text = "Battlegroup PV"
        '
        'txtBattlegroupName
        '
        Me.txtBattlegroupName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBattlegroupName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.txtBattlegroupName.Location = New System.Drawing.Point(8, 32)
        Me.txtBattlegroupName.Name = "txtBattlegroupName"
        Me.txtBattlegroupName.Size = New System.Drawing.Size(304, 22)
        Me.txtBattlegroupName.TabIndex = 0
        Me.txtBattlegroupName.Text = "Battlegroup Name"
        '
        'lblBGName
        '
        Me.lblBGName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblBGName.Location = New System.Drawing.Point(8, 8)
        Me.lblBGName.Name = "lblBGName"
        Me.lblBGName.Size = New System.Drawing.Size(136, 24)
        Me.lblBGName.TabIndex = 31
        Me.lblBGName.Text = "Battlegroup Name"
        '
        'pnlIcons
        '
        Me.pnlIcons.BackColor = System.Drawing.Color.PowderBlue
        Me.pnlIcons.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlIcons.Controls.Add(Me.lblClickitbaby)
        Me.pnlIcons.Controls.Add(Me.lblFriendly)
        Me.pnlIcons.Controls.Add(Me.lblEnemy)
        Me.pnlIcons.Controls.Add(Me.lblOwner)
        Me.pnlIcons.Controls.Add(Me.picFriendly)
        Me.pnlIcons.Controls.Add(Me.picEnemy)
        Me.pnlIcons.Controls.Add(Me.picOwner)
        Me.pnlIcons.Location = New System.Drawing.Point(328, 288)
        Me.pnlIcons.Name = "pnlIcons"
        Me.pnlIcons.Size = New System.Drawing.Size(224, 72)
        Me.pnlIcons.TabIndex = 28
        '
        'lblClickitbaby
        '
        Me.lblClickitbaby.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblClickitbaby.Location = New System.Drawing.Point(4, 55)
        Me.lblClickitbaby.Name = "lblClickitbaby"
        Me.lblClickitbaby.Size = New System.Drawing.Size(208, 16)
        Me.lblClickitbaby.TabIndex = 15
        Me.lblClickitbaby.Text = "Click on an icon to change its image."
        '
        'lblFriendly
        '
        Me.lblFriendly.Location = New System.Drawing.Point(152, 2)
        Me.lblFriendly.Name = "lblFriendly"
        Me.lblFriendly.Size = New System.Drawing.Size(56, 16)
        Me.lblFriendly.TabIndex = 14
        Me.lblFriendly.Text = "Friendly"
        Me.lblFriendly.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblEnemy
        '
        Me.lblEnemy.Location = New System.Drawing.Point(84, 2)
        Me.lblEnemy.Name = "lblEnemy"
        Me.lblEnemy.Size = New System.Drawing.Size(48, 17)
        Me.lblEnemy.TabIndex = 13
        Me.lblEnemy.Text = "Enemy"
        Me.lblEnemy.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblOwner
        '
        Me.lblOwner.Location = New System.Drawing.Point(12, 2)
        Me.lblOwner.Name = "lblOwner"
        Me.lblOwner.Size = New System.Drawing.Size(48, 16)
        Me.lblOwner.TabIndex = 12
        Me.lblOwner.Text = "Owner"
        Me.lblOwner.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'picFriendly
        '
        Me.picFriendly.BackColor = System.Drawing.Color.Black
        Me.picFriendly.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picFriendly.Location = New System.Drawing.Point(162, 21)
        Me.picFriendly.Name = "picFriendly"
        Me.picFriendly.Size = New System.Drawing.Size(33, 33)
        Me.picFriendly.TabIndex = 11
        Me.picFriendly.TabStop = False
        '
        'picEnemy
        '
        Me.picEnemy.BackColor = System.Drawing.Color.Black
        Me.picEnemy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picEnemy.Location = New System.Drawing.Point(90, 21)
        Me.picEnemy.Name = "picEnemy"
        Me.picEnemy.Size = New System.Drawing.Size(33, 33)
        Me.picEnemy.TabIndex = 10
        Me.picEnemy.TabStop = False
        '
        'picOwner
        '
        Me.picOwner.BackColor = System.Drawing.Color.Black
        Me.picOwner.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picOwner.Location = New System.Drawing.Point(18, 21)
        Me.picOwner.Name = "picOwner"
        Me.picOwner.Size = New System.Drawing.Size(33, 33)
        Me.picOwner.TabIndex = 9
        Me.picOwner.TabStop = False
        '
        'btnAddBattleGroup
        '
        Me.btnAddBattleGroup.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnAddBattleGroup.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAddBattleGroup.Location = New System.Drawing.Point(323, 167)
        Me.btnAddBattleGroup.Name = "btnAddBattleGroup"
        Me.btnAddBattleGroup.Size = New System.Drawing.Size(101, 23)
        Me.btnAddBattleGroup.TabIndex = 43
        Me.btnAddBattleGroup.Text = "Add Group"
        Me.btnAddBattleGroup.UseVisualStyleBackColor = False
        '
        'Button2
        '
        Me.Button2.BackColor = System.Drawing.Color.LightSteelBlue
        Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.Button2.Location = New System.Drawing.Point(323, 196)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(101, 23)
        Me.Button2.TabIndex = 44
        Me.Button2.Text = "Remove Group"
        Me.Button2.UseVisualStyleBackColor = False
        '
        'ctlCreateBattleGroups
        '
        Me.Controls.Add(Me.pnlCreateBattlegroup)
        Me.Name = "ctlCreateBattleGroups"
        Me.Size = New System.Drawing.Size(568, 400)
        Me.pnlCreateBattlegroup.ResumeLayout(False)
        Me.pnlCreateBattlegroup.PerformLayout()
        Me.pnlIcons.ResumeLayout(False)
        CType(Me.picFriendly, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picEnemy, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picOwner, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public WriteOnly Property CurrentGame() As CampaignerGameData
        Set(ByVal Value As CampaignerGameData)
            ptrCurrentGame = Value
        End Set
    End Property

    Public Property Unit() As BattlegroupChit
        Get
            Return ptrUnit
        End Get
        Set(ByVal Value As BattlegroupChit)
            ptrUnit = Value
            If Not ptrUnit Is Nothing Then
                ListMembers()
            End If
        End Set
    End Property

    Private Sub ListMembers()
        Dim un As UnitType

        tvwBattlegroupView.Nodes.Clear()

        battleGroupNode = New CampaignerItemTreeNode
        battleGroupNode = AddBattleGroup(ptrUnit)

        tvwBattlegroupView.Nodes.Add(battleGroupNode)


    End Sub

#Region "Member Listing Functions"

    Private Function AddBattleGroup(ByRef BG As BattlegroupChit) As CampaignerItemTreeNode
        Dim node As New CampaignerItemTreeNode
        node.ItemType = CampaignerItem_cgd.Battlegroup

        node.Text = BG.Name
        node.Item = BG


        Dim un As ChitMember
        For Each un In BG.members
            If un.UnitType = GroundChitClass_cgd.Battlegroup Then
                Dim bgnode As New ChitTreeNode(un)
                '// we'll probably have to do extra stuff. :(
                node.Nodes.Add(bgnode)
            Else
                Dim unnode As New ChitTreeNode(un)
                node.Nodes.Add(unnode)
            End If

            'If TypeOf un Is BattleGroup Then
            '    Dim bgNode As CampaignerItemTreeNode = AddBattleGroup(un)
            '    node.Nodes.Add(bgNode)
            'Else
            '    Dim unnode As CampaignerItemTreeNode = AddUnit(un)
            '    node.Nodes.Add(unnode)
            'End If
        Next

        Return node

    End Function

    Private Function AddUnit(ByRef unit As UnitType) As CampaignerItemTreeNode
        Dim node As New CampaignerItemTreeNode
        node.ItemType = CampaignerItem_cgd.Unit

        node.Text = unit.Name
        node.Item = unit
        'ListElements(unit, node)
        ' add this unit's icon to the imagelist and add 2 for the image, since there are two icons for elements and element groups
        imlUnitIcons.Images.Add(unit.Icon(cmplib01.IconImageIndex_cgd.Owner))

        node.ImageIndex = imlUnitIcons.Images.Count - 1
        node.SelectedImageIndex = imlUnitIcons.Images.Count - 1

        Return node

    End Function

    Private Sub ListElements(ByRef unit As BattlegroupChit, ByRef node As CampaignerItemTreeNode)
        'Try

        '    Dim group As ElementGroup
        '    Dim EleGroup As GroupableElements = unit.ChitElements

        '    If unit.ChitElements.Count = 0 Then Exit Sub

        '    For Each group In EleGroup.Groups
        '        Dim GroupNode As New CampaignerItemTreeNode
        '        GroupNode.Text = group.GroupName
        '        GroupNode.ItemType = CampaignerItem_cgd.ElementGroup
        '        GroupNode.Item = group
        '        GroupNode.ImageIndex = 0
        '        GroupNode.SelectedImageIndex = 0
        '        node.Nodes.Add(GroupNode)
        '    Next

        '    Dim ele As GroupableElement
        '    Dim optionText As String
        '    Dim opt As ElementOption

        '    '// first post the Non-grouped elements
        '    For Each ele In EleGroup
        '        If ele.GroupName = "<Ungrouped>" Then
        '            Dim ungroupedelenode As New CampaignerItemTreeNode

        '            optionText = " "
        '            For Each opt In ele.Options
        '                Dim optNode As New TreeNode
        '                optNode.Text = opt.ElementOptionTypeName & " (" & opt.ElementOptionPointCost & ")"
        '                optNode.SelectedImageIndex = 2
        '                optNode.ImageIndex = 2
        '                ungroupedelenode.Nodes.Add(optNode)
        '            Next

        '            ungroupedelenode.Text = ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")"
        '            ungroupedelenode.ImageIndex = 1
        '            ungroupedelenode.SelectedImageIndex = 1
        '            ungroupedelenode.ItemType = CampaignerItem_cgd.Element
        '            ungroupedelenode.Item = ele
        '            node.Nodes.Add(ungroupedelenode)

        '        End If
        '    Next

        '    '// now go through all of the elements and find the group it belongs to
        '    For Each ele In EleGroup
        '        Dim nodie As TreeNode
        '        For Each nodie In node.Nodes
        '            If ele.GroupName = nodie.Text Then
        '                Dim eleNode As New CampaignerItemTreeNode

        '                optionText = " "
        '                For Each opt In ele.Options
        '                    Dim optNode As New TreeNode
        '                    optNode.Text = opt.ElementOptionTypeName & " (" & opt.ElementOptionPointCost & ")"
        '                    optNode.SelectedImageIndex = 2
        '                    optNode.ImageIndex = 2
        '                    eleNode.Nodes.Add(optNode)
        '                Next

        '                eleNode.Text = ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")"
        '                eleNode.ImageIndex = 1
        '                eleNode.SelectedImageIndex = 1
        '                eleNode.ItemType = CampaignerItem_cgd.Element
        '                eleNode.Item = ele
        '                nodie.Nodes.Add(eleNode)
        '            End If
        '        Next
        '    Next
        'Catch ex As Exception
        '    HandleException("frmChitTreeHierarchy.BuildTree", ex)
        'End Try
    End Sub

#End Region

    Private Sub btnAddNewUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNewUnit.Click
        '// we have to add this unit to the selected battlegroup

        Dim frm As New frmUnitSelection
        frm.ShowDialog(ptrCurrentGame)
        Exit Sub

        If _selectedGroup Is Nothing Then
            MessageBox.Show("You must select a group for the new unit.", "Please Select Group", MessageBoxButtons.OK)
        End If


        Dim newUnit As New ChitUnitTypeMember
        Dim f As New frmNewSingleUnit

        Try
            f.CurrentGame = ptrCurrentGame
            f.Unit = newUnit

            f.ShowDialog()

            If Not f.CancelPressed Then
                _selectedGroup.members.add(f.Unit)
                ListMembers()
            End If

            TallyPointValue()
            CalculateProperties()

        Catch ex As Exception
            HandleException("ctlCreateBattleGroups.btnAddNewUnit_Click", ex)
        End Try
    End Sub

    Private Sub TallyPointValue()
        Dim bu As BattlegroupChit
        Dim pv As Integer

        For Each bu In ptrUnit.members
            pv += bu.deployedpointvalue
        Next

        ptrUnit.CurrentPV = pv
        ptrUnit.deployedpointvalue = pv
        lblBGPointValue.Text = pv

        RaiseEvent PointValueChanged(pv)

    End Sub

    Private Sub CalculateProperties()
        '// calculates the properties for the battlegroup depending on the units that it is comprised of.
        '// if all the units have the same movement class, thats the one used. Otherwise we use mixed.

        If ptrUnit.members.Count = 0 Then Exit Sub

        ptrUnit.calculateProperties()

        'Dim bestlosRange As Single
        'Dim bestlosPower As Single
        'Dim bestzocRange As Single
        'Dim worstmovementSpeed As Single = 50000
        'Dim primaryMoveClass As Integer
        'Dim bSingleMoveClass As Boolean = True
        'Dim bUsesZOC As Boolean
        'Dim bgUnit As BattlegroupChit

        'primaryMoveClass = ptrUnit.Units.item(0).MovementClassID

        'ptrUnit.Size = 0

        'For Each bgUnit In ptrUnit.Units

        '    ptrUnit.Size += bgUnit.Size

        '    If bgUnit.UsesZOC Then
        '        If bgUnit.ZOCRange > bestzocRange Then
        '            bestzocRange = bgUnit.ZOCRange
        '        End If
        '        bUsesZOC = True
        '    End If

        '    If bgUnit.LOS > bestlosRange Then
        '        bestlosRange = bgUnit.LOS
        '    End If
        '    If bgUnit.LOSPower > bestlosPower Then
        '        bestlosPower = bgUnit.LOSPower
        '    End If

        '    If bgUnit.MovementSpeed < worstmovementSpeed Then
        '        worstmovementSpeed = bgUnit.MovementSpeed
        '    End If

        '    If bgUnit.MovementClassID <> primaryMoveClass Then
        '        bSingleMoveClass = False
        '    End If

        'Next

        'ptrUnit.LOS = bestlosRange
        'ptrUnit.LOSPower = bestlosPower
        'ptrUnit.MovementSpeed = worstmovementSpeed

        'If bSingleMoveClass = True Then
        '    ptrUnit.MovementClassID = primaryMoveClass
        'Else
        '    ptrUnit.MovementClassID = 8 ' mixed
        'End If

        'If bUsesZOC Then
        '    '// ZOC is going to be dependent on the sum of the other units in it. Use the area of the 
        '    ' zoc ranges for each unit... something...
        '    ptrUnit.ZOCRange = bestzocRange

        '    ptrUnit.UsesZOC = True
        'Else
        '    ptrUnit.UsesZOC = False
        'End If


    End Sub

    Private Sub picIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picOwner.Click, picEnemy.Click, picFriendly.Click
        SetNewIcon(sender)
    End Sub

    Private Sub SetNewIcon(ByRef pic As PictureBox)
        '// sets the icon into the picture
        Try
            Dim fOpen As New OpenFileDialog
            fOpen.Filter = "Picture Files | *.bmp; *.jpg"
            fOpen.ShowDialog()

            pic.Image = Image.FromFile(fOpen.FileName)

            ' now we'll update all the images
            If Not ptrUnit Is Nothing Then
                ptrUnit.icon = picOwner.Image
                'ptrUnit.icon = picEnemy.Image
                'ptrUnit.Icon(IconImageIndex_cgd.SameFaction) = picFriendly.Image
            End If

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub btnEditUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditUnit.Click
        '// determine which member is selected and then allow for edits
        If tvwBattlegroupView.SelectedNode Is Nothing Then Exit Sub

        If TypeOf tvwBattlegroupView.SelectedNode Is CampaignerItemTreeNode Then
            Dim citn As CampaignerItemTreeNode = tvwBattlegroupView.SelectedNode
            If citn.ItemType = CampaignerItem_cgd.Unit Then
                EditBattleGroupMember(citn.Item)
            End If
        End If

    End Sub

    Private Sub EditBattleGroupMember(ByRef member As ChitUnitTypeMember)
        Dim f As New frmNewSingleUnit
        f.CurrentGame = ptrCurrentGame
        f.Unit = member
        f.ShowDialog()
        ListMembers()
        TallyPointValue()
    End Sub

    Private Sub btnRemoveUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveUnit.Click
        If tvwBattlegroupView.SelectedNode Is Nothing Then Exit Sub

        If TypeOf tvwBattlegroupView.SelectedNode Is CampaignerItemTreeNode Then
            Dim citn As CampaignerItemTreeNode = tvwBattlegroupView.SelectedNode
            If citn.ItemType = CampaignerItem_cgd.Unit Then
                ptrUnit.members.remove(citn.Item)
                ListMembers()
                TallyPointValue()
            End If
        End If

    End Sub

    Private Sub txtBattlegroupName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBattlegroupName.TextChanged
        If Not ptrUnit Is Nothing Then
            ptrUnit.Name = txtBattlegroupName.Text
        End If
    End Sub

    Private Sub tvwBattlegroupView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwBattlegroupView.AfterSelect
        Try
            '// we have to find out what type of item was selected, bg or bgmember
            If tvwBattlegroupView.SelectedNode Is Nothing Then Exit Sub
            If TypeOf tvwBattlegroupView.SelectedNode.Tag Is BattlegroupChit Then
                _selectedGroup = tvwBattlegroupView.SelectedNode.Tag
            Else
                '// the parent
                _selectedGroup = tvwBattlegroupView.SelectedNode.Parent.Tag
            End If

            '// we need to update the images of the battlegroup. Yahbaby.


        Catch ex As Exception

        End Try
    End Sub

End Class

